﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Text;

/// <summary>
/// Summary description for JavascriptUtil
/// </summary>
public class JavascriptUtil
{
	public JavascriptUtil()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static void OpenNewTab(UpdatePanel u, string url){
        JavascriptUtil.LoadScript(u, "openNewTab('"+url+"')");
    }
    public static void OpenNewTab(Page p, string url)
    {
        JavascriptUtil.LoadScript(p, "openNewTab('" + url + "')");
    }
    public static void LoadScript(UpdatePanel u, string script)
    {
        ScriptManager.RegisterStartupScript(u, u.GetType(), "script", script, true);
    }
    public static void LoadMessage(UpdatePanel u, bool isSuccess, string message) {
        string cls = "msgSuccess";
        if (!isSuccess)
        {
            cls = "msgFailed";
        }
        ScriptManager.RegisterStartupScript(u, u.GetType(), "script",
            "AjaxPanelResponseMessage('" + message + "','" + cls + "');", true);
    }
    public static void LoadMessage(Page page, bool isSuccess, string message)
    {
        string cls = "msgSuccess";
        if (!isSuccess)
        {
            cls = "msgFailed";
        }
        page.ClientScript.RegisterStartupScript(page.GetType(), "script", "<script>AjaxPanelResponseMessage('" + message + "','" + cls + "');</script>");
    }
    public static void LoadScript(Page page, string script)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "script", script);
    }
    public static void ShowPopup(Page page, UpdatePanel u, string title, string content, char popupType) {
        //plugin jquery.reveal.js
        //Write HTML
        StringBuilder sb = new StringBuilder();
        sb.Append("<div id='modal' class='popup'><div id='heading'>"+title+"</div>");
        sb.Append("<div id='content'><p>"+content+"</p><a href='javascript:;' class='button close'>Đồng ý</a></div></div>");

        ScriptManager.RegisterStartupScript(u, u.GetType(), "script", "$('body').append(\""+sb.ToString()+"\");showPopup()", true);
    }
}
public class PopupType {
    public const char Alert = 'A';
}